package org.cem.backend;

import javax.security.auth.login.LoginException;

import org.cem.security.CemSecurityPlugin;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
import org.eclipse.wb.swt.BrowserUtil;

/**
 * Configures the initial size and appearance of a workbench window.
 */
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {

	private static final Color COLOR_SHELL_BG = new Color(Display.getDefault(), 229, 236, 243);

	public ApplicationWorkbenchWindowAdvisor(
			IWorkbenchWindowConfigurer configurer) {
		super(configurer);
	}

	public ActionBarAdvisor createActionBarAdvisor(
			IActionBarConfigurer configurer) {
		return new ApplicationActionBarAdvisor(configurer);
	}

	public void preWindowOpen() {
		IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
		configurer.setShowMenuBar(true);
		configurer.setShowCoolBar(true);
		configurer.setShowPerspectiveBar(true);
		configurer.setShowStatusLine(true);
		configurer.setTitle("RBP Demo");
		configurer.setShellStyle(SWT.NO_TRIM);
		// UICallBack.activate("default");
		
//		try {
//			CemSecurityPlugin.getLoginContext().login();
//		} catch (LoginException e) {
//			try {
//				CemSecurityPlugin.getLoginContext().logout();
//			} catch (LoginException e1) {
//				e1.printStackTrace();
//			} finally {
////				BrowserUtil.openURL(BrowserUtil.getCurrentBrowserURL());
//			}
//		}
	}

	public void postWindowOpen() {
		IWorkbenchWindow window = getWindowConfigurer().getWindow();
		Shell shell = window.getShell();
		shell.setMaximized(true);
		shell.setBackground(COLOR_SHELL_BG);
	}

}
